package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 客户端发送当前角色移动消息
 */
public class WorldMap_CurrRoleMoveProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 13008; }

    public Float TargetPosX; //目标坐标X
    public Float TargetPosY; //目标坐标Y
    public Float TargetPosZ; //目标坐标Z
    public Long ServerTime; //客户端发包时的服务器时间（毫秒）
    public Integer NeedTime; //客户端移动所需时间（毫秒）

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteFloat(TargetPosX);
            dataStream.WriteFloat(TargetPosY);
            dataStream.WriteFloat(TargetPosZ);
            dataStream.WriteLong(ServerTime);
            dataStream.WriteInt(NeedTime);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static WorldMap_CurrRoleMoveProto GetProto(byte[] buffer) {
        WorldMap_CurrRoleMoveProto proto = new WorldMap_CurrRoleMoveProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.TargetPosX = dataStream.ReadFloat();
            proto.TargetPosY = dataStream.ReadFloat();
            proto.TargetPosZ = dataStream.ReadFloat();
            proto.ServerTime = dataStream.ReadLong();
            proto.NeedTime = dataStream.ReadInt();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}